<template>
  <a-modal v-model="visible" title="重置月统计" @cancel='cancel' @ok='sure'>
    <!-- 搜索条件 -->
    <div class="table-page-search-wrapper">
      <a-spin :spinning='loading' >
        <a-form layout="inline" style='text-align: center'>
          <a-form-item :label="null">
            <a-month-picker @change="dateChange" placeholder="选择月份" :disabledDate='disabledDate'>
              <template slot="renderExtraFooter">
                <span style='color: red'>注：仅限近14个月内重置</span>
              </template>
            </a-month-picker>
          </a-form-item>
          （重置过程大约需要5-10分钟，请勿频繁重置）
        </a-form>
      </a-spin>
    </div>

  </a-modal>
</template>

<script>
import moment from 'moment'
import ReportsHandleMonthlyService from '@/myService/ReportsHandleMonthlyService'

export default {
  data(){
    return{
      visible:false,
      params:{
        month:'',
        nowDate:''
      },
      loading:false,
    }
  },
  methods:{
    open(){
      this.visible=true;
    },
    cancel(){
      this.visible=false;
    },
    sure(){
      if(this.params.month!==''){
        this.loading=true;
        ReportsHandleMonthlyService.handlerStatisticsMonthly(this.params).then(res=>{
          this.$message.success("已提交，正在后台处理")
        }).finally(()=>{
          this.loading=false;
          this.cancel();
        })
      }else {
        this.$message.info("请选择月份")
      }
    },
    disabledDate(current) {
      return current && (current > moment().endOf('day') || current < moment().subtract(14, "month"));
    },
    dateChange(val){
      if(val!==null){
        this.params.month=moment(val).format("YYYYMM")
        this.params.nowDate=moment(val).add(1,'month').format('YYYY-MM-01 00:00:00')
      }
      else {
        this.params={
          month:'',
          nowDate:''
        }
      }
    }

  }
}
</script>

<style scoped>

</style>